<template>
  <div class="color-picker">
    <div
      v-for="color in colors"
      :key="color"
      class="color-block"
      :style="{ backgroundColor: color }"
      :class="{ active: selectedColor === color }"
      @click="selectColor(color)"
      @mouseover="hoverColor = color"
      @mouseleave="hoverColor = null"
    ></div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      selectedColor: null,
      hoverColor: null,
      colors: [
        "#FF6B6B",
        "#4ECDC4",
        "#45B7D1",
        "#96CEB4",
        "#FFEEAD",
        "#FF9F76",
        "#CC527A",
        "#E8175D",
        "#474747",
        "#363636",
        "#A7226E",
        "#EC2049",
      ],
    };
  },
  methods: {
    selectColor(color) {
      this.selectedColor = this.selectedColor === color ? null : color;
      this.$emit("color-selected", this.selectedColor);
    },
  },
};
</script>

<style scoped>
.color-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(24px, 1fr));
  gap: 12px;
  padding: 1px;
  background: #f8f9fa;
  border-radius: 4px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.color-block {
  position: relative;
  width: 22px;
  height: 22px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.color-block:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.color-block.active {
  transform: scale(1.1);
  box-shadow: 0 0 0 3px white, 0 0 0 5px currentColor;
}

.color-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
}

.color-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -4px;
  border-width: 4px;
  border-style: solid;
  border-color: rgba(0, 0, 0, 0.8) transparent transparent transparent;
}
</style>
